package async;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author fei.fang
 * @date 2021/8/26
 **/
public class ReentrantLockConditionTest implements Runnable{

    private static Lock lock = new ReentrantLock();

    private static Condition condition = lock.newCondition();

    @Override public void run(){
        try{
            lock.lock();
            System.out.println("thread waiting");
            condition.await();

            System.out.println("thread going");
        }catch (InterruptedException e){
            e.printStackTrace();
        }finally{
            lock.unlock();
        }
    }

    public static void main(String[] args) throws InterruptedException{
        ReentrantLockConditionTest test = new ReentrantLockConditionTest();
        Thread t = new Thread(test);
        t.start();
        Thread.sleep(1000);

        lock.lock();
        condition.signal();
        lock.unlock();

    }
}
